import os

class ListDirNode:
    @classmethod
    def INPUT_TYPES(cls):
        return {
            "required": {
                "dir_path": ("STRING", {"default": "/", "multiline": False}),
            }
        }

    RETURN_TYPES = ("LIST",)
    RETURN_NAMES = ("entries",)
    FUNCTION = "list_dir"
    CATEGORY = "AI训练/path_manager"

    def list_dir(self, dir_path):
        try:
            entries = []
            for entry in os.listdir(dir_path):
                full_path = os.path.join(dir_path, entry)
                entries.append(full_path)
            return (entries,)
        except Exception as e:
            print(f"读取目录失败: {e}")
            return ([],)

# 节点注册
NODE_CLASS_MAPPINGS = {
    "ListDirNode": ListDirNode,
}

NODE_DISPLAY_NAME_MAPPINGS = {
    "ListDirNode": "目录内容列举节点",
} 